<template>
	<view class="theme_bg_vice_color">
		<cu-custom id="nav" :isBack="true" :backColor="'text-black'">
			<block slot="backText">
				<view class="text-black ">
					充值中心
				</view>
			</block>
		</cu-custom>
		<view class="padding-sm">
			<view class="cu-card bg-brown radius text-center padding-tb">
				<view class="text-lg">我的余额</view>
				<view class="text-bold margin-top-xs" style="font-size: 50rpx;">￥{{balance}}</view>
			</view>
			<view class="margin-tb-sm">
				<view class="">选择充值金额</view>
				<view class="margin-top-sm">
					<view class="flex justify-between bg-white padding-sm margin-bottom-sm" v-for="(item,index) in dataList" :key="index">
						<view>
							<view class="flex justify-start">
								<view class="cu-tag bg-red sm radius">优惠</view>
								<view class="text-bold">充值</view>
							</view>
							<view class="text-sm">充{{item.recharge}}送{{item.discount}}</view>
						</view>
						<view class="cu-btn bg-black round" @click="RechargeBalance(item.id)">￥{{item.recharge}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList:[],
				balance:0,
			};
		},
		onLoad() {
			this.$u.api.getMoneySet().then(res=>{
				this.dataList=res.data
			})
			this.getBlanceInfo()
		},
		methods:{
			RechargeBalance(id){
				this.$u.api.RechargeBalance({
					userId:this.vuex_user.id,
					moneySetId:id
				}).then(res=>{
					if(res.code===200){
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: res.data.timeStamp,
							nonceStr: res.data.nonceStr,
							package: 'prepay_id=' + res.data.prepayId,
							signType: res.data.signType,
							paySign: res.data.paySign,
							success: res1 => {
								console.log('success:' + JSON.stringify(res1));
								this.$Toast('成功','success',1000,setTimeout(()=>{
									this.getBlanceInfo()
								},1000))
							},
							fail: err => {
								console.log('fail:' + JSON.stringify(err));
							}
						});
					}
				})
			},
			getBlanceInfo(){
				this.$u.api.userBalanceInfo({
					userId:this.vuex_user.id
				}).then(res=>{
					this.balance=res.data.balance
					this.$u.vuex('vuex_memberbalance',res.data)
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
